//
//  SMoreViewController.m
//  Gunz
//
//  Created by Joggy on 16/5/23.
//  Copyright © 2016年 NUPT. All rights reserved.
//

#import "SMoreViewController.h"
#import "STableViewCell1.h"
#import "STableViewCell2.h"
#import "GZConst.h"

@interface SMoreViewController ()<UITableViewDelegate, UITableViewDataSource> {
    
    UITableView *table;
    NSArray *titleList;
    
}

@end

@implementation SMoreViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self prepareForNav];
    [self prepareForLayout];
    titleList = @[
                  @[@"声音提醒", @"震动提醒"],
                  @[@"系统推荐通知", @"清空消息列表"]
                  ];
}

- (void)prepareForNav {
    [super prepareForNav];
    self.title = @"更多设置";
    //导航左按键
    UIImage *image = [UIImage imageNamed:@"all_back"];
    UIButton *leftBarButton = [UIButton buttonWithType:UIButtonTypeSystem];
    leftBarButton.frame = CGRectMake(0, 0, image.size.width, image.size.height);
    leftBarButton.layer.position = CGPointMake(22, 22);
    [leftBarButton setImage:[image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] forState:UIControlStateNormal];
    [leftBarButton addTarget:self action:@selector(back) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftBarButton];
}

- (void)prepareForLayout {
    [super prepareForLayout];
    table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, screenWidth, screenHeight - 64) style:UITableViewStylePlain];
    table.delegate = self;
    table.dataSource = self;
    table.backgroundColor = [UIColor clearColor];
    table.tableHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, screenWidth, 10)];
    table.showsVerticalScrollIndicator = false;
    table.separatorStyle = UITableViewCellSelectionStyleBlue;
    table.separatorColor = [UIColor colorWithRed:0.85 green:0.85 blue:0.85 alpha:1];
    [table registerClass:[STableViewCell1 class] forCellReuseIdentifier:@"SMCell1"];
    [table registerClass:[STableViewCell2 class] forCellReuseIdentifier:@"SMCell2"];
    [self.view addSubview:table];
}

- (void)back {
    [self.navigationController popViewControllerAnimated:true];
}

#pragma 代理方法

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:true];
    
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 47;
}

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 2;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 2;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return 10;
}

-(UIView*)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, screenWidth, 10)];
    v.backgroundColor = [UIColor clearColor];
    return v;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    if(indexPath.section == 1 && indexPath.row == 1) {
        STableViewCell2 *cell = [tableView dequeueReusableCellWithIdentifier:@"SMCell2"];
        cell.textLabel.text = @"清空消息列表";
        cell.backgroundColor = [UIColor colorWithRed:0.9765 green:0.9765 blue:0.9843 alpha:1];
        cell.textLabel.textColor = [UIColor colorWithRed:0.298 green:0.345 blue:0.4235 alpha:1];
        return cell;
    }
    else {
        STableViewCell1 *cell = [tableView dequeueReusableCellWithIdentifier:@"SMCell1"];
        NSArray *arr = titleList[indexPath.section];
        cell.textLabel.text = arr[indexPath.row];
        cell.backgroundColor = [UIColor colorWithRed:0.9765 green:0.9765 blue:0.9843 alpha:1];
        cell.textLabel.textColor = [UIColor colorWithRed:0.298 green:0.345 blue:0.4235 alpha:1];
        return cell;
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
